package com.mybatis.example.plugs;


import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;

import java.sql.PreparedStatement;

@Intercepts(value = {
        @Signature(type = ParameterHandler.class,method = "setParameters",args = {PreparedStatement.class})
})
public class ParameterHandlerPlug implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {

        System.out.println("---------------------------------参数插件----------------------");

        DefaultParameterHandler handler = (DefaultParameterHandler) invocation.getTarget();
        System.out.println("parameterObject:"+handler.getParameterObject());
        PreparedStatement ps = (PreparedStatement) invocation.getArgs()[0];
        System.out.println("数据库预处理对象："+ ps);
        System.out.println("---------------------------------参数插件----------------------");

        return invocation.proceed();
    }
}
